#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn],ans[maxn],sz[maxn],n;
vector<int>g[maxn];
void dfs1(LL u,LL fa){
    sz[u]=1;
    dp[u]=0;
    for(LL i=0;i<g[u].size();i++){
        LL v=g[u][i];
        if(v==fa) continue;
        dfs1(v,u);
        dp[u]+=dp[v]+sz[v];
        sz[u]+=sz[v];
    }
}
void dfs2(LL u,LL fa){
    for(LL i=0;i<g[u].size();i++){
        LL v=g[u][i];
        if(v==fa) continue;
        dp[v]=dp[u]+1*(n-sz[v])-1*sz[v];
        dfs2(v,u);
    }
}
int main(void){
    n=read();
    for(LL i=1;i<n;i++){
        LL u,v;u=read();v=read();
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs1(1,-1);
    dfs2(1,-1);
    for(LL i=1;i<=n;i++){
        printf("%lld\n",dp[i]);
    }
   	return 0;
}
